package com.gskj.commonutils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author :CodingFarmer_码农  Connor(康纳)_郭
 * @date : 12:40 20.5.13
 * @Company : http://www.gskj.com
 * @Version : 1.0
 * <p>
 * 设置 返回结果类型的 实体类
 */
@Data
public class ResultJson implements Serializable, ResultCode {

    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "状态码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<>();

    // 私有化 构造器
    private ResultJson() {
    }

    // 成功静态方法
    public static ResultJson success() {
        ResultJson json = new ResultJson();
        json.setSuccess(true);
        json.setCode(SUCCESS);
        json.setMessage("成功");
        return json;
    }

    // 失败静态方法
    public static ResultJson error() {
        ResultJson json = new ResultJson();
        json.setSuccess(false);
        json.setCode(ERROR);
        json.setMessage("失败");
        return json;
    }

    // 链式调用
    public ResultJson success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public ResultJson message(String message) {
        this.setMessage(message);
        return this;
    }

    public ResultJson data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public ResultJson data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }

    public ResultJson code(Integer code) {
        this.setCode(code);
        return this;
    }
}
